#![allow(dead_code)]

mod ast;
mod lexing;
mod lox;

use lox::Lox;

fn run_prompt() {
    use std::io;

    let mut input = String::new();

    let mut lox = lox::TLox::new();
    while let Ok(_n) = io::stdin().read_line(&mut input) {
        lox.eval(&input);
        input.clear();
    }
}

fn run_file(file_name: &str) {
    use std::fs;
    // 文件都不存在直接 panic 算了
    let content = fs::read_to_string(file_name).expect("can not open the file");

    let mut lox = lox::TLox::new();
    lox.eval(&content);
}

fn main() {
    let args: Vec<String> = std::env::args().collect();

    if args.len() == 1 {
        run_prompt();
    } else if args.len() == 2 {
        run_file(&args[1]);
    } else {
        println!("Usage: ylox <script>");
    }
}
